if exists (select 1 from sysobjects where name = 'set_userrights' and type = 'P')
begin
   drop procedure set_userrights
   print 'Procedure: set_userrights deleted ...'
end
go
create procedure set_userrights(
  @username          varchar(35)   = 'planer',
  @loginname         varchar(35)   = 'planer',
  @password          varchar(256)  = 'personalplaner',
  @beschreibung      varchar(250)  = 'Haupt User',
  @userrights        int           = 1,
  @mandid            char(2)       = 'PA',
  @retval            int           = 0 output
)
as
begin
  set nocount on

  insert into userrights 
              (username,
               loginname,
               password,
               beschreibung,
               userrights,
               mandid)
       values (@username,
               @loginname,
               convert(varbinary(256), pwdencrypt(ISNULL(@password,''))),
               ISNULL(@beschreibung,''),
               @userrights,
               @mandid)

end
go
print 'Procedure: set_userrights done ...'
go
grant exec on set_userrights to prsadmins with grant option
go
grant exec on set_userrights to prsusers
go

